<script setup lang="ts">
import { ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";

import { IconSelect } from "@/components/ReIcon";

import {
  menuTypeOptions,
  showLinkOptions,
  keepAliveOptions,
  hiddenTagOptions,
  showParentOptions,
  frameLoadingOptions
} from "./utils/enums";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    deletable: 0,
    pid: 0,
    title: "",
    name: "",
    path: "",
    component: "",
    rank: 99,
    redirect: " ",
    icon: ""
  })
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="82px"
  >
    <el-row :gutter="30">
      <re-col>
        <el-form-item
          v-if="
            !newFormInline.sid &&
            (newFormInline.type * 1 == 10 || newFormInline.type * 1 == 20)
          "
          label="上级菜单"
        >
          <el-cascader
            v-model="newFormInline.parentTreeCode"
            class="w-full"
            :options="newFormInline.higherMenuOptions"
            :props="{
              value: 'treeCode',
              label: 'title',
              emitPath: false,
              checkStrictly: true
            }"
            clearable
            filterable
            placeholder="请选择上级菜单"
          >
            <template #default="{ node, data }">
              <span>{{ data.menuName }}</span>
              <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
            </template>
          </el-cascader>
        </el-form-item>
      </re-col>

      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="菜单名称" prop="menuName">
          <el-input
            v-model="newFormInline.menuName"
            clearable
            placeholder="请输入菜单名称"
          />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="权限标识" prop="permission">
          <el-input
            v-model="newFormInline.permission"
            clearable
            placeholder="请输入权限标识"
          />
        </el-form-item>
      </re-col>

      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="菜单类型">
          <el-radio-group v-model="newFormInline.type">
            <el-radio :value="0">目录 </el-radio>
            <el-radio :value="10">菜单 </el-radio>
            <el-radio :value="20">按钮 </el-radio>
          </el-radio-group>
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="菜单排序">
          <el-input-number
            v-model="newFormInline.viewSort"
            class="!w-full"
            :min="1"
            :max="9999"
            controls-position="right"
          />
        </el-form-item>
      </re-col>
      <re-col v-if="newFormInline.type !== 0" :value="12" :xs="24" :sm="24">
        <el-form-item label="路由路径" prop="path">
          <el-input
            v-model="newFormInline.path"
            clearable
            placeholder="请输入路由路径"
          />
        </el-form-item>
      </re-col>

      <!-- <re-col v-show="newFormInline.menuType === 0" :value="12" :xs="24" :sm="24">
        <el-form-item label="路由重定向">
          <el-input v-model="newFormInline.redirect" clearable placeholder="请输入默认跳转地址" />
        </el-form-item>
      </re-col> -->

      <re-col v-show="newFormInline.type !== 20" :value="12" :xs="24" :sm="24">
        <el-form-item label="菜单图标">
          <IconSelect v-model="newFormInline.icon" class="w-full" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="是否可删除">
          <el-radio-group v-model="newFormInline.deletable">
            <el-radio :value="0">可以删除 </el-radio>
            <el-radio :value="1">不可以删除 </el-radio>
          </el-radio-group>
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="是否显示">
          <el-radio-group v-model="newFormInline.visible">
            <el-radio :value="0">显示 </el-radio>
            <el-radio :value="1">隐藏 </el-radio>
          </el-radio-group>
        </el-form-item>
      </re-col>
      <!-- <re-col
        v-show="newFormInline.menuType !== 3"
        :value="12"
        :xs="24"
        :sm="24"
      >
        <el-form-item label="右侧图标">
          <el-input
            v-model="newFormInline.extraIcon"
            clearable
            placeholder="菜单名称右侧的额外图标"
          />
        </el-form-item>
      </re-col> -->
    </el-row>
  </el-form>
</template>
